import { useUserinfo } from "@/stores/userinfo"
export const permission = {
    mounted(el:HTMLElement, binding:{value:string[]}) {
        const {scope}=useUserinfo()
        if(!binding.value.find(item=>scope.includes(item))){
            el.parentNode?.removeChild(el)
        }
    }
}


//自定义指令
export const role =(el:HTMLElement,binding:{value:string})=>{
    const {roles}=useUserinfo()

    if(!(binding.value && roles.includes(binding.value))){
        el.style.display='none'
    }
}

//全局插件
export const autherization={
    install(app: any) {
        app.directive('permission', permission)
        app.directive('role', role)
    }
}